package kr.pfg.applications.captureyourscreen.utils
{
	import flash.desktop.Clipboard;
	import flash.desktop.ClipboardFormats;
	import flash.display.BitmapData;
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	import flash.utils.ByteArray;
	
	import kr.as3.utils.JPGEncoder;
	
	public class CapturedImageSaver
	{
		public function CapturedImageSaver()
		{
			
		}
		
		static public function getToSaveAsJPGClipboard( bmd:BitmapData, name:String ):Clipboard
		{
			var imageByte:ByteArray = new JPGEncoder( 85 ).encode( bmd );
		 	var imageFile:File = File.applicationStorageDirectory.resolvePath( name );
		 	var imageFileStream:FileStream = new FileStream();
		 	imageFileStream.open( imageFile, FileMode.WRITE );
		 	imageFileStream.writeBytes( imageByte );
		 	imageFileStream.close();
		 	
		 	var clipboard:Clipboard = new Clipboard();
		 	clipboard.setData( ClipboardFormats.FILE_LIST_FORMAT, [ imageFile ] );
		 	
		 	return clipboard;
		}

	}
}